import request from '@/utils/request'
import { transformObj } from '@/utils/formatUtil'

//管理后台
export function manageLogin(data) {
  return request({
    url: '/background/login',
    method: 'post',
    data: data
  })
}
export function login(data) {
  return request({
    url: '/background/login',
    method: 'post',
    data: data
  })
}

export function getInfo(token) {
  return request({
    url: '/user/info',
    method: 'get',
    params: { token }
  })
}

export function logout() {
  return request({
    url: '/background/logout',
    method: 'get'
  })
}

export function checkLoginManage() {
  return request({
    url: '/background/isLogin',
    method: 'get'
  })
}
//c端
/************       用户相关        ***************/
//退出登录
export function logOut() {
  return request({
    url: '/lgout',
    method: 'get'
  })
}
//检查是否登录接口
export function checkLogin() {
  return request({
    url: '/cklg',
    method: 'get'
  })
}

//账号密码登录
export function normalLoginApi(data) {
  return request({
    url: '/lgin/normal',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    method: 'post',
    data: transformObj(data)
  })
}

//邮箱密码登录
export function authLoginApi(data) {
  return request({
    url: '/lgin/auth',
    headers: { 'content-type': 'application/x-www-form-urlencoded' },
    method: 'post',
    data: transformObj(data)
  })
}

//发送验证码接口
export function getAuthCodeApi(data) {
  return request({
    url: '/sckcode',
    method: 'post',
    data: transformObj(data)
  })
}

//注册接口
export function doRegist(data) {
  return request({
    url: '/reg',
    method: 'post',
    data: transformObj(data)
  })
}

//查询nickName接口
export function getNickName(data) {
  return request({
    url: '/u/getMgmNickName',
    method: 'post',
    data: transformObj(data)
  })
}

//注册时检查用户是否已存在
export function checkNameExists(name) {
  return request({
    url: '/u/ckEmailReg?userName='+name,
    method: 'get'
  })
}
